package cn.wolfcode.productServer.web.controller;

import cn.wolfcode.productServer.domain.Product;
import cn.wolfcode.productServer.service.IProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class ProductController {
    @Autowired
    private IProductService productService;

    @Value("${server.port}")
    private String port;

    @RequestMapping("/get")
    public Product get(Long id){
        log.info("商品服务的表现层");
        //测试Feign重试的次数
        System.out.println("调用商品服务");
        //模拟网络延迟
       /* try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        Product product = productService.get(id);
        product.setPname(product.getPname()+"data from"+port);
        return product;
    }
}
